
document.addEventListener('DOMContentLoaded', function () {
    window.addEventListener('load', function () {
        var tab = document.querySelector('.tab')
        for (var i = 0; i < tab.children.length; i++) {
            tab.children[i].addEventListener('mouseenter', function () {
                for (var i = 0; i < tab.children.length; i++) {
                    tab.children[i].className = '';
                }
                this.className = 'c'
            })
        }

    })

    window.addEventListener('load', function () {
        var body = document.querySelector('body');
        for (var i = 1; i < body.children.length; i++) {
            body.children[i].setAttribute('index', i);
            body.children[i].addEventListener('mousewheel', function (e) {
                e = e || window.event;
                if (e.wheelDelta) {  //判断浏览器IE，谷歌滑轮事件             
                    if (e.wheelDelta > 0) { //当滑轮向上滚动时
                        var index = this.getAttribute('index');
                        var childwidth = body.offsetHeight;
                        animate1(body, (index - 2) * childwidth);

                    }
                }

            })

            body.children[i].addEventListener('mousewheel', function (e) {
                e = e || window.event;
                if (e.wheelDelta) {  //判断浏览器IE，谷歌滑轮事件             
                    if (e.wheelDelta < 0) { //当滑轮向下滚动时
                        var index = this.getAttribute('index');
                        var childwidth = body.offsetHeight;
                        animate2(body, (index) * childwidth);
                    }
                }
            })
        }

        function animate1(obj, target, callback) {
            clearInterval(obj.timer);
            obj.timer = setInterval(function () {
                var step = (target - window.pageYOffset) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                if (window.pageYOffset <= target) {
                    clearInterval(obj.timer);
                    callback && callback();
                }
                window.scroll(0, window.pageYOffset + step)
            }, 15);
        }

        function animate2(obj, target, callback) {
            clearInterval(obj.timer);
            obj.timer = setInterval(function () {
                var step = (target - window.pageYOffset) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                if (window.pageYOffset >= target) {
                    clearInterval(obj.timer);
                    callback && callback();
                }
                window.scroll(0, window.pageYOffset + step)
            }, 15);
        }

    })
    window.addEventListener('load', function () {
        var t = document.querySelector('.t')
        for (var i = 0; i < t.children.length; i++) {
            t.children[i].addEventListener('mouseenter', function () {
                for (var i = 0; i < t.children.length; i++) {
                    t.children[i].className = '';
                }
                this.className = 'c'
            })
        }
    })
})